/*
 * File: p16.c
 *
 * Code generated for Simulink model 'p16'.
 *
 * Model version                  : 1.3
 * Simulink Coder version         : 25.1 (R2025a) 21-Nov-2024
 * C/C++ source code generated on : Sun Jul  6 15:34:06 2025
 *
 * Target selection: ert.tlc
 * Embedded hardware selection: Intel->x86-64 (Windows64)
 * Code generation objectives: Unspecified
 * Validation result: Not run
 */

#include "p16.h"
#include "rtwtypes.h"

/* Named constants for Chart: '<Root>/Chart' */
#define p16_IN_state0                  ((uint8_T)1U)
#define p16_IN_state1                  ((uint8_T)2U)

/* Block signals (default storage) */
B_p16_T p16_B;

/* Block states (default storage) */
DW_p16_T p16_DW;

/* Real-time model */
static RT_MODEL_p16_T p16_M_;
RT_MODEL_p16_T *const p16_M = &p16_M_;

/* Model step function */
void p16_step(void)
{
  real_T rtb_x;

  /* DiscretePulseGenerator: '<Root>/Pulse Generator' */
  if ((p16_DW.clockTickCounter < 50) && (p16_DW.clockTickCounter >= 0)) {
    rtb_x = 0.5;
  } else {
    rtb_x = 0.0;
  }

  if (p16_DW.clockTickCounter >= 99) {
    p16_DW.clockTickCounter = 0;
  } else {
    p16_DW.clockTickCounter++;
  }

  /* End of DiscretePulseGenerator: '<Root>/Pulse Generator' */

  /* Chart: '<Root>/Chart' */
  if (p16_DW.is_active_c3_p16 == 0) {
    p16_DW.is_active_c3_p16 = 1U;
    p16_DW.is_c3_p16 = p16_IN_state0;
    p16_B.count0 = 0.0;
  } else if (p16_DW.is_c3_p16 == p16_IN_state0) {
    if (rtb_x > 0.0) {
      p16_B.count0 = 0.0;
      p16_DW.is_c3_p16 = p16_IN_state1;
      p16_B.count1 = 0.0;
    } else {
      p16_B.count0++;
    }

    /* case IN_state1: */
  } else if (rtb_x <= 0.0) {
    p16_B.count1 = 0.0;
    p16_DW.is_c3_p16 = p16_IN_state0;
    p16_B.count0 = 0.0;
  } else {
    p16_B.count1++;
  }

  /* End of Chart: '<Root>/Chart' */

  /* Chart: '<Root>/Chart1' */
  if (p16_DW.is_active_c1_p16 == 0) {
    p16_DW.is_active_c1_p16 = 1U;
    p16_DW.is_c1_p16 = p16_IN_state0;
    p16_B.count_i = 0.0;
  } else {
    switch (p16_DW.is_c1_p16) {
     case p16_IN_state0:
      break;

     default:
      /* case IN_state1: */
      p16_DW.is_c1_p16 = p16_IN_state0;
      p16_B.count_i = 0.0;
      break;
    }
  }

  /* End of Chart: '<Root>/Chart1' */

  /* Chart: '<Root>/Chart2' */
  if (p16_DW.is_active_c2_p16 == 0) {
    p16_DW.is_active_c2_p16 = 1U;
    p16_DW.is_c2_p16 = p16_IN_state0;
    p16_B.count = 0.0;
  } else {
    switch (p16_DW.is_c2_p16) {
     case p16_IN_state0:
      break;

     default:
      /* case IN_state1: */
      p16_DW.is_c2_p16 = p16_IN_state0;
      p16_B.count = 0.0;
      break;
    }
  }

  /* End of Chart: '<Root>/Chart2' */
}

/* Model initialize function */
void p16_initialize(void)
{
  /* (no initialization code required) */
}

/* Model terminate function */
void p16_terminate(void)
{
  /* (no terminate code required) */
}

/*
 * File trailer for generated code.
 *
 * [EOF]
 */
